package com.inspire.springboot.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author ：inspire
 * @date ：Created in 2024/8/22 10:21
 * @description：
 * @modified By：inspire
 * @version:
 */
@RestController
public class SabiArraysPfmController {

    @PostMapping("/bizPfmTest/{id}")
    @ResponseBody
    public String bizPfmTest(@PathVariable("id") int id){
        for(int i=0;i<10000;i++){
            paic_buildMerchantDTOList("aaa");
            if(i==5000){

            }
        }
        return "bizPfmTest-success!";
    }

    @PostMapping("/bizPfmTest2/{id}")
    @ResponseBody
    public String bizPfmTest2(@PathVariable("id") int id){
        for(int i=0;i<10000;i++){
            paic_buildMerchantDTOList("aaa");
            if(i==5000){

            }
        }
        return "bizPfmTest2-success!";
    }


    @PostMapping("/bizPfmTest3/{id}")
    @ResponseBody
    public String bizPfmTest3(@PathVariable("id") int id){
        for(int i=0;i<10000;i++){
            paic_buildMerchantDTOList("aaa");
            if(i==5000){

            }
        }
        return "bizPfmTest3-success!";
    }

    private List<String> paic_buildMerchantDTOList(String offlineMerchantInfoResDTO) {
        List<String> offlineMerchantDTOList = new CopyOnWriteArrayList<>();
        List<String> list = Arrays.asList("A123", "B123", "C123", "A321");
        Optional.ofNullable(offlineMerchantInfoResDTO)
                .ifPresent(list1 -> list.stream().parallel().forEach(offlineMerchantDTO -> {
                            try {
                                findMerchantLocation(offlineMerchantDTO);
                                offlineMerchantDTOList.add(offlineMerchantDTO);
                            } catch (Exception ex) {
                                //注释......
                            }
                        })
                );
        return offlineMerchantDTOList;

    }

    private void findMerchantLocation(String offlineMerchantDTO) {

    }
}
